package com.fr.chart.plot;

import com.fr.base.background.Background;
import com.fr.base.background.ColorBackground;
import com.fr.base.background.IntervalColorBackground;
import com.fr.base.xml.BaseXMLUtils;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import com.fr.chart.GeneralInfo;
import com.fr.chart.axis.CategoryAxis;
import com.fr.chart.axis.TextAttr;
import com.fr.chart.axis.ValueAxis;
import com.fr.chart.base.equals.Equals;
import com.fr.chart.core.glyph.AxisGlyph;
import com.fr.chart.core.glyph.CategoryAxisGlyph;
import com.fr.chart.core.glyph.DateAxisGlyph;
import com.fr.chart.core.glyph.PlotGlyph;
import com.fr.chart.core.glyph.StockPlotGlyph;
import com.fr.chart.core.glyph.TextGlyph;
import com.fr.chart.core.glyph.ValueAxisGlyph;
import com.fr.chart.marker.DowJonesMarker;
import com.fr.chart.marker.Marker;
import com.fr.data.ChartData;
import com.fr.report.io.xml.ReportXMLUtils;
import java.awt.Color;
import java.awt.Insets;

public class StockPlot extends Plot
{
  private static final long serialVersionUID = 1L;
  public static final int HIGH_LOW_CLOSE = 0;
  public static final int OPEN_HIGH_LOW_CLOSE = 1;
  public static final int VOLUME_HIGH_LOW_CLOSE = 2;
  public static final int VOLUME_OPEN_HIGH_LOW_CLOSE = 3;
  private int subType = 0;
  private CategoryAxis categoryAxis = new CategoryAxis();
  private ValueAxis volumeAxis = new ValueAxis();
  private ValueAxis priceAxis = new ValueAxis();
  private int closeLineStyle = 0;
  private Color closeLineColor = Color.black;
  private Marker closeMarker = new DowJonesMarker();
  private int highLowLineStyle = 1;
  private Color highLowLineColor = Color.gray;
  private int upBarBorderLineStyle = 1;
  private Color upBarBorderLineColor = Color.red;
  private Background upBarBackground = ColorBackground.getInstance(Color.white);
  private int downBarBorderLineStyle = 1;
  private Color downBarBorderLineColor = Color.green;
  private Background downBarBackground = ColorBackground.getInstance(Color.white);
  private boolean bgStagger = false;
  private Color bgColor = Color.white;

  public StockPlot()
  {
    this.categoryAxis.setPosition(3);
    this.priceAxis.setPosition(2);
    this.volumeAxis.setPosition(4);
  }

  public StockPlot(int paramInt)
  {
    this.subType = paramInt;
    this.categoryAxis.setPosition(3);
    this.priceAxis.setPosition(2);
    this.volumeAxis.setPosition(4);
  }

  public Insets createOuterIntsets()
  {
    return new Insets(10, 20, 20, 20);
  }

  public boolean match4GUI(Plot paramPlot)
  {
    return ((super.match4GUI(paramPlot)) && (((StockPlot)paramPlot).getSubType() == getSubType()));
  }

  public int getSubType()
  {
    return this.subType;
  }

  public void setSubType(int paramInt)
  {
    this.subType = paramInt;
  }

  public CategoryAxis getCategoryAxis()
  {
    return this.categoryAxis;
  }

  public void setCategoryAxis(CategoryAxis paramCategoryAxis)
  {
    this.categoryAxis = paramCategoryAxis;
  }

  public ValueAxis getVolumeAxis()
  {
    return this.volumeAxis;
  }

  public void setVolumeAxis(ValueAxis paramValueAxis)
  {
    this.volumeAxis = paramValueAxis;
  }

  public ValueAxis getPriceAxis()
  {
    return this.priceAxis;
  }

  public void setPriceAxis(ValueAxis paramValueAxis)
  {
    this.priceAxis = paramValueAxis;
  }

  public int getHighLowLineStyle()
  {
    return this.highLowLineStyle;
  }

  public void setHighLowLineStyle(int paramInt)
  {
    this.highLowLineStyle = paramInt;
  }

  public Color getHighLowLineColor()
  {
    return this.highLowLineColor;
  }

  public void setHighLowLineColor(Color paramColor)
  {
    this.highLowLineColor = paramColor;
  }

  public int getCloseLineStyle()
  {
    return this.closeLineStyle;
  }

  public void setCloseLineStyle(int paramInt)
  {
    this.closeLineStyle = paramInt;
  }

  public Color getCloseLineColor()
  {
    return this.closeLineColor;
  }

  public void setCloseLineColor(Color paramColor)
  {
    this.closeLineColor = paramColor;
  }

  public Marker getCloseMarker()
  {
    return this.closeMarker;
  }

  public void setCloseMarker(Marker paramMarker)
  {
    this.closeMarker = paramMarker;
  }

  public int getUpBarBorderLineStyle()
  {
    return this.upBarBorderLineStyle;
  }

  public void setUpBarBorderLineStyle(int paramInt)
  {
    this.upBarBorderLineStyle = paramInt;
  }

  public Color getUpBarBorderLineColor()
  {
    return this.upBarBorderLineColor;
  }

  public void setUpBarBorderLineColor(Color paramColor)
  {
    this.upBarBorderLineColor = paramColor;
  }

  public Background getUpBarBackground()
  {
    return this.upBarBackground;
  }

  public void setUpBarBackground(Background paramBackground)
  {
    this.upBarBackground = paramBackground;
  }

  public int getDownBarBorderLineStyle()
  {
    return this.downBarBorderLineStyle;
  }

  public void setDownBarBorderLineStyle(int paramInt)
  {
    this.downBarBorderLineStyle = paramInt;
  }

  public Color getDownBarBorderLineColor()
  {
    return this.downBarBorderLineColor;
  }

  public void setDownBarBorderLineColor(Color paramColor)
  {
    this.downBarBorderLineColor = paramColor;
  }

  public Background getDownBarBackground()
  {
    return this.downBarBackground;
  }

  public void setDownBarBackground(Background paramBackground)
  {
    this.downBarBackground = paramBackground;
  }

  private double getMaxVolumeValue(ChartData paramChartData)
  {
    if ((this.subType == 2) || (this.subType == 3))
    {
      double d = 0.0D;
      for (int i = 0; i < paramChartData.getCategoryLabelCount(); ++i)
        d = (paramChartData.getValueAt(0, i).doubleValue() > d) ? paramChartData.getValueAt(0, i).doubleValue() : d;
      return d;
    }
    return 0.0D;
  }

  private double getMaxPriceValue(ChartData paramChartData)
  {
    if ((this.subType == 2) || (this.subType == 3))
    {
      double d = 0.0D;
      for (int i = 0; i < paramChartData.getCategoryLabelCount(); ++i)
        for (int j = 1; j < paramChartData.getSeriesCount(); ++j)
          d = (paramChartData.getValueAt(j, i).doubleValue() > d) ? paramChartData.getValueAt(j, i).doubleValue() : d;
      return d;
    }
    return getMaxValueFromData(paramChartData);
  }

  public void setBgStagger(boolean paramBoolean)
  {
    this.bgStagger = paramBoolean;
  }

  public boolean getBgStagger()
  {
    return this.bgStagger;
  }

  public void setBgColor(Color paramColor)
  {
    this.bgColor = paramColor;
  }

  public Color getBgColor()
  {
    return this.bgColor;
  }

  public PlotGlyph createPlotGlyph(ChartData paramChartData)
  {
    StockPlotGlyph localStockPlotGlyph = new StockPlotGlyph();
    install4PlotGlyph(localStockPlotGlyph, paramChartData);
    createAxisGlyph(localStockPlotGlyph, paramChartData);
    createErrTextGlyph(localStockPlotGlyph);
    return localStockPlotGlyph;
  }

  public void install4PlotGlyph(StockPlotGlyph paramStockPlotGlyph, ChartData paramChartData)
  {
    super.install4PlotGlyph(paramStockPlotGlyph, paramChartData);
    paramStockPlotGlyph.setSubType(this.subType);
    paramStockPlotGlyph.setHighLowLineColor(this.highLowLineColor);
    paramStockPlotGlyph.setHighLowLineStyle(this.highLowLineStyle);
    paramStockPlotGlyph.setDownBarBackground(this.downBarBackground);
    paramStockPlotGlyph.setDownBarBorderLineColor(this.downBarBorderLineColor);
    paramStockPlotGlyph.setDownBarBorderLineStyle(this.downBarBorderLineStyle);
    paramStockPlotGlyph.setUpBarBackground(this.upBarBackground);
    paramStockPlotGlyph.setUpBarBorderLineColor(this.upBarBorderLineColor);
    paramStockPlotGlyph.setUpBarBorderLineStyle(this.upBarBorderLineStyle);
  }

  private void createAxisGlyph(StockPlotGlyph paramStockPlotGlyph, ChartData paramChartData)
  {
    Object localObject1;
    Object localObject2;
    if ((checkDate(paramChartData)) && (this.categoryAxis.isDateAxis()))
    {
      localObject1 = new DateAxisGlyph(this.categoryAxis);
      double[] arrayOfDouble = getDateRange(paramChartData);
      ((DateAxisGlyph)localObject1).initMinMaxValue(arrayOfDouble[0], arrayOfDouble[1]);
    }
    else
    {
      localObject1 = new CategoryAxisGlyph(this.categoryAxis);
    }
    paramStockPlotGlyph.setCategoryAxisGlyph((CategoryAxisGlyph)localObject1);
    int i = 0;
    int j = paramChartData.getCategoryLabelCount();
    while (i < j)
    {
      ((CategoryAxisGlyph)localObject1).addCategoryLabel((paramChartData.getCategoryLabel(i) == null) ? "" : paramChartData.getCategoryLabel(i));
      ++i;
    }
    ValueAxisGlyph localValueAxisGlyph = new ValueAxisGlyph(this.priceAxis);
    localValueAxisGlyph.initMinMaxValue(getMinValueFromData(paramChartData), getMaxPriceValue(paramChartData));
    paramStockPlotGlyph.setPriceAxisGlyph(localValueAxisGlyph);
    if ((this.subType == 2) || (this.subType == 3))
    {
      localObject2 = new ValueAxisGlyph(this.volumeAxis);
      ((ValueAxisGlyph)localObject2).initMinMaxValue(getMinValueFromData(paramChartData), getMaxVolumeValue(paramChartData));
      paramStockPlotGlyph.setVolumeAxisGlyph((ValueAxisGlyph)localObject2);
    }
    if (this.bgStagger)
    {
      localObject2 = new IntervalColorBackground();
      ((IntervalColorBackground)localObject2).setColor(this.bgColor);
      ((IntervalColorBackground)localObject2).setPosition(this.priceAxis.getPosition());
      paramStockPlotGlyph.getInfo().setBackground((Background)localObject2);
    }
    paramStockPlotGlyph.axisExtends((AxisGlyph)localObject1);
  }

  private void createErrTextGlyph(StockPlotGlyph paramStockPlotGlyph)
  {
    int i = paramStockPlotGlyph.getSeriesSize();
    if ((i == 3) && (getSubType() == 0))
      return;
    if (i == 4)
    {
      if (getSubType() != 1)
        if (getSubType() == 2);
    }
    else
    {
      if ((i == 5) && (getSubType() == 3))
        return;
      TextGlyph localTextGlyph = new TextGlyph(getDataErrorText(getSubType()), new TextAttr());
      paramStockPlotGlyph.setErrTextGlyph(localTextGlyph);
    }
  }

  private String getDataErrorText(int paramInt)
  {
    StringBuffer localStringBuffer = new StringBuffer("Error! To create this stock chart, arrange your chart data in this order: ");
    if (paramInt == 0)
      localStringBuffer.append(" high price, low price, closing price.");
    else if (paramInt == 1)
      localStringBuffer.append(" opening price,");
    else if (paramInt == 2)
      localStringBuffer.append(" volume traded,");
    else if (paramInt == 3)
      localStringBuffer.append(" volume traded, opening price,");
    return localStringBuffer.toString();
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    super.readXML(paramXMLableReader);
    if (paramXMLableReader.isChildNode())
    {
      String str2;
      String str1 = paramXMLableReader.getTagName();
      if ("Type".equals(str1))
      {
        if ((str2 = paramXMLableReader.getAttr("value")) != null)
          this.subType = Integer.parseInt(str2);
      }
      else if ("CategoryAxis".equals(str1))
      {
        paramXMLableReader.readXMLObject(new XMLReadable(this)
        {
          private final StockPlot this$0;

          public void readXML()
          {
            if (paramXMLableReader.getTagName().equals("CategoryAxis"))
              StockPlot.access$002(this.this$0, (CategoryAxis)paramXMLableReader.readXMLObject(new CategoryAxis()));
          }
        });
      }
      else if ("PriceAxis".equals(str1))
      {
        paramXMLableReader.readXMLObject(new XMLReadable(this)
        {
          private final StockPlot this$0;

          public void readXML()
          {
            if (paramXMLableReader.getTagName().equals("ValueAxis"))
              StockPlot.access$102(this.this$0, (ValueAxis)paramXMLableReader.readXMLObject(new ValueAxis()));
          }
        });
      }
      else if ("VolumeAxis".equals(str1))
      {
        paramXMLableReader.readXMLObject(new XMLReadable(this)
        {
          private final StockPlot this$0;

          public void readXML()
          {
            if (paramXMLableReader.getTagName().equals("ValueAxis"))
              StockPlot.access$202(this.this$0, (ValueAxis)paramXMLableReader.readXMLObject(new ValueAxis()));
          }
        });
      }
      else if ("Close".equals(str1))
      {
        paramXMLableReader.readXMLObject(new XMLReadable(this)
        {
          private final StockPlot this$0;

          public void readXML()
          {
            if (paramXMLableReader.isAttr())
            {
              String str;
              if ((str = paramXMLableReader.getAttr("style")) != null)
                StockPlot.access$302(this.this$0, Integer.parseInt(str));
              if ((str = paramXMLableReader.getAttr("color")) != null)
                StockPlot.access$402(this.this$0, new Color(Integer.parseInt(str), true));
            }
            else if ((paramXMLableReader.isChildNode()) && (paramXMLableReader.getTagName().equals("Marker")))
            {
              StockPlot.access$502(this.this$0, (Marker)ReportXMLUtils.readXMLable(paramXMLableReader));
            }
          }
        });
      }
      else if ("HighLow".equals(str1))
      {
        paramXMLableReader.readXMLObject(new XMLReadable(this)
        {
          private final StockPlot this$0;

          public void readXML()
          {
            if (paramXMLableReader.isAttr())
            {
              String str;
              if ((str = paramXMLableReader.getAttr("style")) != null)
                StockPlot.access$602(this.this$0, Integer.parseInt(str));
              if ((str = paramXMLableReader.getAttr("color")) != null)
                StockPlot.access$702(this.this$0, new Color(Integer.parseInt(str), true));
            }
          }
        });
      }
      else if ("UpBar".equals(str1))
      {
        paramXMLableReader.readXMLObject(new XMLReadable(this)
        {
          private final StockPlot this$0;

          public void readXML()
          {
            if (paramXMLableReader.isAttr())
            {
              String str;
              if ((str = paramXMLableReader.getAttr("style")) != null)
                StockPlot.access$802(this.this$0, Integer.parseInt(str));
              if ((str = paramXMLableReader.getAttr("color")) != null)
                StockPlot.access$902(this.this$0, new Color(Integer.parseInt(str), true));
            }
            else if ((paramXMLableReader.isChildNode()) && ("Background".equals(paramXMLableReader.getTagName())))
            {
              StockPlot.access$1002(this.this$0, BaseXMLUtils.readBackground(paramXMLableReader));
            }
          }
        });
      }
      else if ("DownBar".equals(str1))
      {
        paramXMLableReader.readXMLObject(new XMLReadable(this)
        {
          private final StockPlot this$0;

          public void readXML()
          {
            if (paramXMLableReader.isAttr())
            {
              String str;
              if ((str = paramXMLableReader.getAttr("style")) != null)
                StockPlot.access$1102(this.this$0, Integer.parseInt(str));
              if ((str = paramXMLableReader.getAttr("color")) != null)
                StockPlot.access$1202(this.this$0, new Color(Integer.parseInt(str), true));
            }
            else if ((paramXMLableReader.isChildNode()) && ("Background".equals(paramXMLableReader.getTagName())))
            {
              StockPlot.access$1302(this.this$0, BaseXMLUtils.readBackground(paramXMLableReader));
            }
          }
        });
      }
      else if ("BG".equals(str1))
      {
        if ((str2 = paramXMLableReader.getAttr("bgStagger")) != null)
          setBgStagger(Boolean.valueOf(str2).booleanValue());
        if ((str2 = paramXMLableReader.getAttr("color")) != null)
          setBgColor(new Color(Integer.parseInt(str2), true));
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("Plot");
    super.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.startTAG("Type").attr("value", this.subType).end();
    if (this.categoryAxis != null)
    {
      paramXMLPrintWriter.startTAG("CategoryAxis");
      this.categoryAxis.writeXML(paramXMLPrintWriter);
      paramXMLPrintWriter.end();
    }
    if (this.priceAxis != null)
    {
      paramXMLPrintWriter.startTAG("PriceAxis");
      this.priceAxis.writeXML(paramXMLPrintWriter);
      paramXMLPrintWriter.end();
    }
    if (this.volumeAxis != null)
    {
      paramXMLPrintWriter.startTAG("VolumeAxis");
      this.volumeAxis.writeXML(paramXMLPrintWriter);
      paramXMLPrintWriter.end();
    }
    paramXMLPrintWriter.startTAG("Close").attr("style", this.closeLineStyle).attr("color", this.closeLineColor.getRGB());
    ReportXMLUtils.writeXMLable(paramXMLPrintWriter, this.closeMarker, "Marker");
    paramXMLPrintWriter.end();
    paramXMLPrintWriter.startTAG("HighLow").attr("style", this.highLowLineStyle).attr("color", this.highLowLineColor.getRGB()).end();
    paramXMLPrintWriter.startTAG("UpBar").attr("style", this.upBarBorderLineStyle).attr("color", this.upBarBorderLineColor.getRGB());
    BaseXMLUtils.writeBackground(paramXMLPrintWriter, this.upBarBackground);
    paramXMLPrintWriter.end();
    paramXMLPrintWriter.startTAG("DownBar").attr("style", this.downBarBorderLineStyle).attr("color", this.downBarBorderLineColor.getRGB());
    BaseXMLUtils.writeBackground(paramXMLPrintWriter, this.downBarBackground);
    paramXMLPrintWriter.end();
    paramXMLPrintWriter.startTAG("BG").attr("bgStagger", this.bgStagger).attr("color", this.bgColor.getRGB()).end();
    paramXMLPrintWriter.end();
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof StockPlot))
      return false;
    StockPlot localStockPlot = (StockPlot)paramObject;
    if (!(super.equals(localStockPlot)))
      return false;
    if (localStockPlot.getSubType() != getSubType())
      return false;
    if (!(Equals.equals(localStockPlot.getCategoryAxis(), getCategoryAxis())))
      return false;
    if (!(Equals.equals(localStockPlot.getVolumeAxis(), getVolumeAxis())))
      return false;
    if (!(Equals.equals(localStockPlot.getPriceAxis(), getPriceAxis())))
      return false;
    if (localStockPlot.getCloseLineStyle() != getCloseLineStyle())
      return false;
    if (!(Equals.equals(localStockPlot.getCloseLineColor(), getCloseLineColor())))
      return false;
    if (!(Equals.equals(localStockPlot.getCloseMarker(), getCloseMarker())))
      return false;
    if (!(Equals.equals(localStockPlot.getHighLowLineColor(), getHighLowLineColor())))
      return false;
    if (localStockPlot.getHighLowLineStyle() != getHighLowLineStyle())
      return false;
    if (!(Equals.equals(localStockPlot.getUpBarBackground(), getUpBarBackground())))
      return false;
    if (!(Equals.equals(localStockPlot.getUpBarBorderLineColor(), getUpBarBorderLineColor())))
      return false;
    if (localStockPlot.getUpBarBorderLineStyle() != getUpBarBorderLineStyle())
      return false;
    if (localStockPlot.getDownBarBorderLineStyle() != getDownBarBorderLineStyle())
      return false;
    if (!(Equals.equals(localStockPlot.getDownBarBackground(), getDownBarBackground())))
      return false;
    if (!(Equals.equals(localStockPlot.getDownBarBorderLineColor(), getDownBarBorderLineColor())))
      return false;
    if (localStockPlot.getBgStagger() != getBgStagger())
      return false;
    return (Equals.equals(localStockPlot.getBgColor(), getBgColor()));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    StockPlot localStockPlot = (StockPlot)super.clone();
    if (this.categoryAxis != null)
      localStockPlot.categoryAxis = ((CategoryAxis)this.categoryAxis.clone());
    if (this.closeMarker != null)
      localStockPlot.closeMarker = ((Marker)this.closeMarker.clone());
    if (this.downBarBackground != null)
      localStockPlot.downBarBackground = ((Background)this.downBarBackground.clone());
    if (this.priceAxis != null)
      localStockPlot.priceAxis = ((ValueAxis)this.priceAxis.clone());
    if (this.upBarBackground != null)
      localStockPlot.upBarBackground = ((Background)this.upBarBackground.clone());
    if (this.volumeAxis != null)
      localStockPlot.volumeAxis = ((ValueAxis)this.volumeAxis.clone());
    return localStockPlot;
  }

  static CategoryAxis access$002(StockPlot paramStockPlot, CategoryAxis paramCategoryAxis)
  {
    return (paramStockPlot.categoryAxis = paramCategoryAxis);
  }

  static ValueAxis access$102(StockPlot paramStockPlot, ValueAxis paramValueAxis)
  {
    return (paramStockPlot.priceAxis = paramValueAxis);
  }

  static ValueAxis access$202(StockPlot paramStockPlot, ValueAxis paramValueAxis)
  {
    return (paramStockPlot.volumeAxis = paramValueAxis);
  }

  static int access$302(StockPlot paramStockPlot, int paramInt)
  {
    return (paramStockPlot.closeLineStyle = paramInt);
  }

  static Color access$402(StockPlot paramStockPlot, Color paramColor)
  {
    return (paramStockPlot.closeLineColor = paramColor);
  }

  static Marker access$502(StockPlot paramStockPlot, Marker paramMarker)
  {
    return (paramStockPlot.closeMarker = paramMarker);
  }

  static int access$602(StockPlot paramStockPlot, int paramInt)
  {
    return (paramStockPlot.highLowLineStyle = paramInt);
  }

  static Color access$702(StockPlot paramStockPlot, Color paramColor)
  {
    return (paramStockPlot.highLowLineColor = paramColor);
  }

  static int access$802(StockPlot paramStockPlot, int paramInt)
  {
    return (paramStockPlot.upBarBorderLineStyle = paramInt);
  }

  static Color access$902(StockPlot paramStockPlot, Color paramColor)
  {
    return (paramStockPlot.upBarBorderLineColor = paramColor);
  }

  static Background access$1002(StockPlot paramStockPlot, Background paramBackground)
  {
    return (paramStockPlot.upBarBackground = paramBackground);
  }

  static int access$1102(StockPlot paramStockPlot, int paramInt)
  {
    return (paramStockPlot.downBarBorderLineStyle = paramInt);
  }

  static Color access$1202(StockPlot paramStockPlot, Color paramColor)
  {
    return (paramStockPlot.downBarBorderLineColor = paramColor);
  }

  static Background access$1302(StockPlot paramStockPlot, Background paramBackground)
  {
    return (paramStockPlot.downBarBackground = paramBackground);
  }
}